package com.study.qqserve.service;

import java.util.HashMap;
import java.util.Iterator;

public class MangerClientThreads {
    private static HashMap<String,ServerContentThread> hm = new HashMap();

    public static void addClientThread(String userId,ServerContentThread serverContentThread){
        hm.put(userId,serverContentThread);
    }

    public static void removeClientThread(String userId){
        hm.remove(userId);
    }

    public  ServerContentThread getClientThread(String userId){
        return hm.get(userId);
    }

    //返回在线用户列表id
    public static String getOnlineUser(){
        Iterator<String> iterator = hm.keySet().iterator();
        String onlineUserIds = "";
        while (iterator.hasNext()){
            onlineUserIds += iterator.next().toString() + " ";
        }
        return onlineUserIds;
    }

    //移除线程
    public static void removeServerContentThread(String userId) {
        hm.remove(userId);
    }

    //得到对应是线程
    public static ServerContentThread getServerContentThread(String userId) {
      return  hm.get(userId);
    }

    //得到所有线程对象
    public static HashMap<String,ServerContentThread> getAllServerContentThread(){
        return hm;
    }

    //判断用户是否在线
    public static boolean isOnline(String userId){
        return hm.containsKey(userId);
    }

}
